package com.flyme.excel.validator;

import com.ycc.vins.excel.ExcelCellValidator;
import com.ycc.vins.util.ValidateResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by lijizhong on 2017/12/15.
 */
@Service
public class LegalInvoiceTaxValidator implements ExcelCellValidator {
    final Pattern p = Pattern.compile("^[0-9]{1,8}([.][0-9]{1,2})?$");

    @Nullable
    @Override
    public ValidateResult apply(String s) {

        if (StringUtils.isBlank(s)) {
            return ValidateResult.pass();
        }
        Matcher m = p.matcher(s);
        if (!m.find()) {
            return ValidateResult.notPass("格式不正确(正确的为数值，支持0---99999999 的正数，可以填写小数点儿后两位)");
        }
        return ValidateResult.pass();
    }
}
